package com.example.strategy.strategy.service;

import com.example.strategy.strategy.MyStrategyContent;
import com.example.strategy.strategy.impl.CatStrategy;
import com.example.strategy.strategy.impl.DogStrategy;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Auther: chenxiuqi
 * @Date: 2020/4/27 20:38
 * @Description:
 */
@Component
public class StrategyService {

    private static List<MyStrategyContent> strategies = new ArrayList<>();

    static {
        strategies.add(new MyStrategyContent("cat",new CatStrategy()));
        strategies.add(new MyStrategyContent("dog",new DogStrategy()));
    }

    public String play(String type){
        List<MyStrategyContent> collect = strategies.stream().filter(x -> x.option(type)).collect(Collectors.toList());
        if (collect!=null&&collect.size()>0){
            return collect.get(0).getMyStrategy().play();
        }else {
            return "我们还有这个宠物哟！~";
        }
    }

}
